package com.lineage.server.clientpackets;

import com.lineage.echo.ClientExecutor;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_Message_YN;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.FaceToFace;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class C_Fight extends ClientBasePacket {
  private static final Log _log = LogFactory.getLog(C_Fight.class);
  
  public void start(byte[] decrypt, ClientExecutor client) {
    try {
      L1PcInstance pc = client.getActiveChar();
      if (pc.isGhost())
        return; 
      L1PcInstance target = FaceToFace.faceToFace(pc);
      if (target != null && !target.isParalyzed()) {
        if (pc.getFightId() != 0) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(633));
          return;
        } 
        if (target.getFightId() != 0) {
          target.sendPackets((ServerBasePacket)new S_ServerMessage(634));
          return;
        } 
        pc.setFightId(target.getId());
        target.setFightId(pc.getId());
        target.sendPackets((ServerBasePacket)new S_Message_YN(630, pc.getName()));
      } 
    } catch (Exception exception) {
    
    } finally {
      over();
    } 
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
